/*
 * TablesView.cpp
 *
 *  Created on: 2011-1-23
 *      Author: Administrator
 */

#include "TablesView.h"
#include "ViewTableRow.h"
#include "TitleItem.h"
#include <eikenv.h>

CTablesView::CTablesView()
	{
	iTableDatas = NULL;
	}

CTablesView::~CTablesView()
	{
	iTableDatas = NULL;
	}

CTablesView* CTablesView::NewL(const TRect& aRect, const CCoeControl* aParent)
	{
	CTablesView* self = CTablesView::NewLC(aRect, aParent);
	CleanupStack::Pop(self);
	return self;
	}

CTablesView* CTablesView::NewLC(const TRect& aRect, const CCoeControl* aParent)
	{
	CTablesView* self = new(ELeave) CTablesView();
	CleanupStack::PushL(self);
	self->ConstructL(aRect, aParent);
	return self;
	}

void CTablesView::Draw(const TRect& aRect) const
	{
	CListBox::Draw(aRect);
	//CGraphicsTool::DrawRect(SystemGc(),aRect,KRgbWhite);
	}

void CTablesView::setTableDatas(CTableDatas* aTableDatas)
	{
	iTableDatas = aTableDatas;
	}

CTableDatas* CTablesView::TableDatas()
	{
	return iTableDatas;
	}

void CTablesView::RefreshTable()
	{
	RemoveAllItems();
	CViewTableRow* row = NULL;
	CViewTableData* tableData = NULL;
	if (iTableDatas && iTableDatas->iTableDatas.Count() > 0)
		{
		for(TInt i = 0; i < iTableDatas->iTableDatas.Count();i++)
			{
			tableData = iTableDatas->iTableDatas[i];
			if (tableData->Title().Length() > 0)
				{
				CTitleItem* title = CTitleItem::NewL(this);
				title->SetTitleColor(KRgbRed);
				title->SetTitleL(tableData->Title());
				title->SetLayout();
				AddListItemL(title);
				}
			if (tableData->iHeaderRowData && tableData->iHeaderRowData->Count() > 0)
				{
				row = CViewTableRow::NewL(this,tableData->iHeaderRowData);
				row->setColumnWidths(tableData->iColumnWidths);
				row->SetTitleColor(KRgbYellow);
				row->SetTitleFont(ApacPlain16());
				row->SetLayout();
				AddListItemL(row);
				}
			for (TInt i = 0; i < tableData->Count(); i++)
				{
				row = CViewTableRow::NewL(this,tableData->getDataRow(i));
				row->setColumnWidths(tableData->iColumnWidths);
				row->SetTitleColor(KRgbWhite);
				row->SetTitleFont(ApacPlain16());
				row->SetLayout();
				AddListItemL(row);
				}
			}
		UpdateControls();
		}
	}
